import random
import time

#定义基础策略类
class Strategy:
    def execute(self,input_data):
        """执行策略"""
        raise NotImplementedError("必须实现execute方法")

#定义具体策略
class SalesStrategy(Strategy):
    def execute(self,input_data):
        #销售策略
        suggestions = [
            "推荐最新款产品，享受限时折扣",
            "参加会员积分活动",
            "组合购买享受更多折扣"
        ]
        return f"销售建议：{random.choice(suggestions)}针对输入： {input_data}"
#定义法务策略
class LegalStrategy(Strategy):
    def execute(self,input_data):
        #法务策略
        suggestions = [
            "推荐最新款产品，享受限时折扣",
            "参加会员积分活动",
            "组合购买享受更多折扣"
        ]
        return f"销售建议：{random.choice(suggestions)}针对输入： {input_data}"

#定义技术策略
class TechnicalStrategy(Strategy):
    def execute(self,input_data):
        #销售策略
        suggestions = [
            "推荐最新款产品，享受限时折扣",
            "参加会员积分活动",
            "组合购买享受更多折扣"
        ]
        return f"销售建议：{random.choice(suggestions)}针对输入： {input_data}"


#定义role-basd agent基础类
class RoleBaseAgent:
    def __init__(self,role,stragegy:Strategy):
        self.role = role
        self.stragegy = stragegy

    def process_request(self,input_data):
        """处理输入请求"""
        processed_data = f"{input_data}处理后"
        response = self.stragegy.execute(processed_data)
        return response

#定义调度器
class AgentDispatcher:
    def __init__(self):
        #注册不同角色的智能体
        self.agents = {
            "sales":RoleBaseAgent("sales",SalesStrategy()),
            "legal":RoleBaseAgent("legal",LegalStrategy()),
            "technical":RoleBaseAgent("technical",TechnicalStrategy()),
        }

    def dispatch(self,role,input_data):
        if role in self.agents:
            agent = self.agents[role]
            return agent.process_request(input_data)
        else:
            return "未找到智能体"

if __name__ == '__main__':
    dispatcher = AgentDispatcher()
    #构造不同的角色
    requests = [
        {"role":"sales","input":"客户询问促销策略"}
    ]
    for request in requests:
        response = dispatcher.dispatch(request['role'],request['input'])
        print(response)
